/*
 * Author :zhaoningbo
 * Date   :2011-8-25 15:44:50
 * Email  :zhaoningbo@hotmail.com
 * Blog   :http://zhaoningbo.iteye.com/
 */
package com.number.mt.await;

import java.io.Serializable;

public class FillDataThread extends Thread implements Serializable {

    private static final long serialVersionUID = -7185272533236889085L;

    private DataWagon dataWagon;
    private int xIndex;
    private CountDownLatchSignals cDLSignals;

    @Override
    public void run() {
        this.fillData();
    }

    public FillDataThread(DataWagon dataWagon, int xIndex,
            CountDownLatchSignals cDLSignals) {
        this.dataWagon = dataWagon;
        this.xIndex = xIndex;
        this.cDLSignals = cDLSignals;
    }

    private void fillData() {
        try {
            long threadId = this.getId();

            this.cDLSignals.getStartSignal().await();

            System.out.println(threadId + ": writing data...");
            Thread.sleep(1200);
            dataWagon.strArr[xIndex][0] = threadId + "";

            this.cDLSignals.getDoneSignal().countDown();

            System.out.println(this.getId() + ": completed!");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}
